The variable NAME
in the PRINT
statement
is a different variable
than NAME$
in the LET
statement:
LET NAME$ = "Sherlock Holmes" PRINT NAME END
The program will run,
but the print statement will print out a 0
because NAME
is a numerical variable
(which starts out with a zero in it, as do all numerical variables.)
When a string variable starts out (the first time it is seen in a
program) it starts out empty.
It contains no characters.
This is like numerical variables starting out containing a zero.
If a string variable is seen for the
first time in a LET
statement,
then it will immediately filled with characters:
LET NAME$ = "Sherlock Holmes" | --------------- | | | | | +--- 2. but the LET statement will immediately | put these characters in it. | +---- 1. when NAME$ is created it will be empty.
Usually you don't need to think about this. However if you misspell a variable name, what your program might do is explained by this rule.
Here is another program:
LET NAME$ = "Professor Moriarty" PRINT NAM$ END
What do you think will be printed on the screen? (Hint: this is yet another trick question.)